package juc.Lock.reentrantLock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class condition implements Runnable{

    public static ReentrantLock lock =new ReentrantLock();
    public static Condition condition=lock.newCondition();
    @Override
    public void run() {
        try {
            lock.lock();
            System.out.println(System.currentTimeMillis()+"获得锁");
            condition.await();
            System.out.println(System.currentTimeMillis()+"继续");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        juc.Lock.reentrantLock.condition c = new condition();
        Thread t = new Thread(c);
        t.start();
        TimeUnit.SECONDS.sleep(2);
        lock.lock();
        System.out.println(System.currentTimeMillis()+"唤醒");
        condition.signal();
        lock.unlock();

    }
}
